package com.enseirb.bdxmap.activity.task;

import java.util.List;

import android.app.ProgressDialog;
import android.content.Context;
import android.os.AsyncTask;

import com.enseirb.bdxmap.activity.MainActivity;
import com.enseirb.bdxmap.activity.listener.MarkerListener;
import com.enseirb.bdxmap.service.UserMarkerService;
import com.enseirb.bdxmap.service.model.UserMarkerBO;

public class UserTask extends AsyncTask<Void, Integer, List<UserMarkerBO>> {
	
	private MarkerListener 		listener;
	private UserMarkerService	userService;
	private ProgressDialog 		progressDialog;
	
	public UserTask	(MarkerListener listener) {
		this.listener = listener;
		this.userService = new UserMarkerService((Context)listener);
		this.progressDialog = new ProgressDialog((Context)listener);
	}
	
	@Override
	protected void onPreExecute() {
		progressDialog.setIndeterminate(false);
		progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
		progressDialog.setCancelable(false);
		progressDialog.setMessage(MainActivity.waitingMessage);
		progressDialog.show();
	}
	
	@Override
	protected List<UserMarkerBO> doInBackground(Void... params) {
		return userService.getData();
	}

	@Override
	protected void onPostExecute(List<UserMarkerBO> userMarkers) {
		progressDialog.dismiss();
		listener.printUserMarkers(userMarkers);
	}
};
